package com.liusr.utils;

import java.util.Random;

/**
 * @author Liusr
 * @date 2023/9/16
 * @package com.liusr.utils
 * @Description: 常用工具类
 */
public class CommonUtil {

	private static final String CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

	/**
	 * 生成不定长随机字符
	 *
	 * @param length 字符长度
	 * @return String
	 */
	public static String generateRandomString(int length) {
		Random random = new Random();
		StringBuilder sb = new StringBuilder(length);

		for (int i = 0; i < length; i++) {
			int randomIndex = random.nextInt(CHARACTERS.length());
			char randomChar = CHARACTERS.charAt(randomIndex);
			sb.append(randomChar);
		}
		return sb.toString();
	}
}
